from datetime import datetime


def create_user_factory(faker):
    """用户对象工厂"""

    def generate_user():
        return {
            "id": faker.uuid4(),
            "username": faker.user_name(),
            "password": faker.password(length=12),
            "last_login": faker.date_time_this_year()
        }

    return generate_user


def batch_user_generator(faker, count=10):
    """批量用户生成器"""
    return (
        {
            "id": faker.uuid4(),
            "name": faker.name(),
            "email": faker.email()
        } for _ in range(count)
    )


def create_boundary_data_factory(faker, field_type, count=5):
    """边界值数据工厂"""

    generators = {
        "int": lambda: [-2 ** 31, 0, 2 ** 31 - 1] + [faker.random_int() for _ in range(count - 3)],
        "float": lambda: [float('-inf'), 0.0, float('inf')] + [faker.pyfloat() for _ in range(count - 3)],
        "string": lambda: ["", "a" * 1000] + [faker.pystr() for _ in range(count - 2)],
        "date": lambda: [datetime.min, datetime.max] + [faker.date_time() for _ in range(count - 2)]
    }
    return generators[field_type]()
